<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Event/classes/PhpFox_ComponentDayEvents.class.php, $Author:  $ */



/** Component for showing day events
 * @version $Id: PhpFox_ComponentDayEvents.class.php 432 2008-04-15 11:51:59Z phpfoxsv $
 * @package module.event
 *   
 */
class PhpFox_Mod_Event_ComponentDayEvents extends BaseComponent
{
    function process()
    {
        $oEventItem = $this->_oModule->getItem('Event');
        /* @var $oEventItem PhpFox_Mod_Event_ItemEvent */
        $oEventService = $this->_oModule->getService('Event');
        /* @var $oEventService PhpFox_Mod_Event_ServiceEvent */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = $this->_oModule->getTemplate();
        $oReq = &App::getRequest();
        $oUrl = &App::getUrl();
        $aOut = array();
        App::loadClass('Pager');
        App::loadClass('Filter');

        $oSecurityService->checkPerm('events', array('read_only', 'full'));
        $oSecurityService->checkAccess('events');
        $iMonth = $oReq->getInt('month');
        $iYear = $oReq->getInt('year');
        $iDay = $oReq->getInt('day');
        if (!$iMonth || !$iYear || !$iDay)
        {
            App::gotoUrl('public.event.calendar');
        }
        $aCategories = array();
        $aCategories[''] = App::format('core.any');
        foreach (App::getTxtFile('event_items.txt') as $sCategory)
        {
            $aCategories[$sCategory] = $sCategory;
        }
        $aFilter = array
        (
        	'type' => array
        	(
        		'value'  => '=',
        		'select' => $aCategories,
        	),
        );
        $oFilter = &new Filter('dayevents', $aFilter);
        $sUser = $oSecurityService->getCurrentUserLogin();
        $iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('public.day_events_count');
        $aCond = array();
        foreach ($oFilter->aConditions as $sCond)
        {
            $aCond[] = $sCond;
        }
        $aCond['month'] = 'IN(' . $iMonth . ',0' . $iMonth . ')';
        $aCond['year'] = '= '.$iYear;
        $aCond['day'] = '= '.$iDay;
        list($aItems, $iCnt) = $oEventService->getEventList($aCond, $iPage, $iPageSize);
        $oPager = &new Pager($iCnt, $iPage, $iPageSize);
        $iPrevDay = $oEventService->prevDay($iDay, $iMonth, $iYear);
        $iNextDay = $oEventService->nextDay($iDay, $iMonth, $iYear);

        $oTpl->assign(array(
        	'aCategories'   => $aCategories,
        	'iNextDay'      => $iNextDay,
        	'aFilter'       => $oFilter->aHtml,
        	'sUImageUrl'    => App::getParam('user.pic.url'),
        	'iPrevDay'      => $iPrevDay,
        	'iCurrentDay'   => mktime(0, 0, 0, $iMonth, $iDay, $iYear),
        	'aItems'        => $aItems,
        	'aPaging'       => ($iCnt) ? $oPager->getInfo($oUrl) : '',
        ));
        $aOut['main'] = $oTpl->fetch('DayEvents.html');
        $aOut['line'] = $oTpl->fetch('DayEventsLine.html');
        return $aOut;
    }
}
?>